<template>
  <div>
    <div class="mt-1">
      <!-- 单元格展示数据 -->
      <van-cell-group>
        <van-field label="拍号" :value="this.ShowDataA.UniqueId" readonly />
        <van-field label="物料号" :value="this.ShowDataA.ProductId" readonly />
        <van-field
          label="物料名称"
          :value="this.ShowDataA.ProductName"
          readonly
        />
        <van-field
          label="生产日期"
          :value="this.ShowDataA.ProductionDate.substring(0, 10)"
          readonly
        />
        <van-field
          label="有效期"
          :value="this.ShowDataA.ExpDate.substring(0, 10)"
          readonly
        />
        <van-field
          label="供应商名称"
          :value="this.ShowDataA.Supplier"
          readonly
        />
        <van-field
          label="生产商名称"
          :value="this.ShowDataA.Producer"
          readonly
        />
        <van-field label="玛氏批次" :value="this.ShowDataA.BatchNo" readonly />
        <van-field
          label="生产线"
          :value="this.ShowDataA.WareHouseName"
          readonly
        />
        <van-field v-model="number" label="数量" />
        <van-field :value="this.ShowDataA.Unit" label="单位" readonly />
      </van-cell-group>
      <van-button type="info" class="mt-1" block @click="handleSubmit"
        >确定</van-button
      >
    </div>
  </div>
</template>

<script>
import "vant/lib/index.less";
import { toast } from "../utils/common";

export default {
  name: "orderNumber",
  data() {
    return {
      valueKW: "",
      number: "",
    };
  },
  props: {
    ShowDataA: {
      type: Object,
    },
  },
  watch: {
    ShowDataA(val) {
      this.ShowDataA = val;
    },
    number(val) {
      this.number = val;
      //this.ShowDataA.StockQuantity = val;
    },
  },
  methods: {
    handleSubmit() {
      console.log(this.number, this.ShowDataA.StockQuantity);
      if (!isNaN(Number(this.number))) {
        if (this.ShowDataA.StockQuantity < Number(this.number)) {
          toast("库存数已超出");
        } else if (
          Number(this.number) == "" ||
          Number(this.number) == undefined ||
          Number(this.number) == null
        ) {
          toast("请输入数量");
        } else {
          this.$emit(
            "get-val",
            this.number,
            this.ShowDataA.UniqueId,
            this.ShowDataA.ProductId
          );
        }
      } else {
        toast("请输入正确的数字");
      }
    },
  },
  mounted() {
    console.log("moun");
    this.number = this.ShowDataA.StockQuantity;
  },
  /*  updated() {
    console.log("up");
    //this.number = this.ShowDataA.StockQuantity;
  }, */
};
</script>

<style scoped>
.ag-theme-alpine {
  border-left-width: 0;
  border-right-width: 0;
  font-size: 0.75rem;
}
.search {
  padding-left: 0;
  padding-right: 0;
}
.van-grid-item__content {
  padding-left: 0;
}
</style>